package jdk8的特性.使用流来收集数据.归约和汇总;

import java.util.List;

import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.reducing;

/**
 * @author idea
 * @data 2018/9/16
 */
public class Test {

    public static void main(String[] args) {
        List<Menu> menus=MockMenuList.mockMenus(10);
        //通过Collectors里面的joining函数直接将字符串内容拼接起来
        String menusName=menus.stream().map(Menu::getName).collect(joining("‘ , ’"));
        System.out.println(menusName);

        String menusName2=menus.stream()
                .map(Menu::getName)
                .collect(reducing( (s1,s2)-> s1+"' , '"+s2 )).get();
        System.out.println(menusName2);

    }
}
